package com.lanchetech.user.controller;

import com.lanchetech.bean.request.LotteryOpportunityPageReq;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.request.UserVoucherReq;
import com.lanchetech.bean.response.BargainEditResp;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.*;
import com.lanchetech.user.service.MarketingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.security.Principal;
import java.util.List;

@Api(value = "营销接口", tags = "营销接口(部分开放接口)")
@RequestMapping("/api/marketing")
@RestController
public class MarketingController {

    @Autowired
    MarketingService marketingService;

    @ApiOperation("获取所有可领取的优惠券分页")
    @PostMapping("/getAllCouponPage")
    public ResultData<BasePageResp<Coupon>> getAllCouponPage(@AuthenticationPrincipal User user, @RequestBody PageReq req) {
        return marketingService.getAllCouponPage(user, req);
    }

    @ApiOperation("领取优惠券")
    @GetMapping("/selectCoupon")
    public BaseResp selectCoupon(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return marketingService.selectCoupon(user, id);
    }

    @ApiOperation(value = "用户每日签到")
    @GetMapping("/getSignIn")
    public ResultData<BigDecimal> getSignIn() {
        return marketingService.getSignIn();
    }


    @ApiOperation(value = "查询今日是否签到")
    @GetMapping("/isSignIn")
    public ResultData<Boolean> isSignIn() {
        return marketingService.isSignIn();
    }

    @ApiOperation(value = "获取当月签到记录")
    @GetMapping("/getMonthSignInRecord")
    public ResultData<List<SignIn>> getMonthSignInRecord(@RequestParam("month") Integer month) {
        return marketingService.getMonthSignInRecord(month);
    }
    @ApiOperation("获取砍价分页")
    @PostMapping("/getBargainPage")
    public ResultData<BasePageResp<BargainSpuItemVO>> getBargainPage(@RequestBody PageReq req) {
        return marketingService.getBargainPage(req);
    }

    @ApiOperation("获取砍价详情")
    @GetMapping("/getBargainDetail")
    public ResultData<BargainEditResp> getBargainDetail(@RequestParam("id") Long id) {
        return marketingService.getBargainDetail(id);
    }

    @ApiOperation("发起砍价")
    @PostMapping("/createBargainRecord")
    public ResultData<Long> createBargainRecord(@RequestBody BargainRecord req) {
        return marketingService.createBargainRecord(req);
    }

    @ApiOperation("获取砍价记录分页")
    @PostMapping("/getBargainRecordPage")
    public ResultData<BasePageResp<BargainRecordVO>> getBargainRecordPage(@RequestBody PageReq req) {
        return marketingService.getBargainRecordPage(req);
    }

    @ApiOperation("获取砍价记录详情")
    @GetMapping("/getBargainRecordDetail")
    public ResultData<BargainRecordVO> getBargainRecordDetail(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return marketingService.getBargainRecordDetail(user, id);
    }

    @ApiOperation("获取好友帮砍明细分页")
    @PostMapping("/getBargainDetailPage")
    public ResultData<BasePageResp<BargainDetailVO>> getBargainDetailPage(@RequestBody PageReq req) {
        return marketingService.getBargainDetailPage(req);
    }

    @ApiOperation("帮好友砍一刀")
    @PostMapping("/createBargainDetail")
    public ResultData<BigDecimal> createBargainDetail(@RequestBody BargainDetail req) {
        return marketingService.createBargainDetail(req);
    }

    @ApiOperation("用户兑换卡分页")
    @PostMapping("/getUserVoucherPage")
    public ResultData<BasePageResp<UserVoucherVO>> getUserVoucherPage(@RequestBody UserVoucherReq req) {
        return marketingService.getUserVoucherPage(req);
    }

    @ApiOperation("获取用户当前是否有正在对此商品进行砍价")
    @GetMapping("/getBargainRecordBySkuId")
    public ResultData<BargainRecord> getBargainRecordBySkuId(@AuthenticationPrincipal User user, @RequestParam("activityId") Long activityId, @RequestParam("skuId") Long skuId) {
        return marketingService.getBargainRecordBySkuId(user, activityId, skuId);
    }

    @ApiOperation("获取抽奖机会分页")
    @PostMapping("/getLotteryOpportunityPage")
    public ResultData<BasePageResp<LotteryOpportunityVO>> getLotteryOpportunityPage(@RequestBody LotteryOpportunityPageReq req) {
        return marketingService.getLotteryOpportunityPage(req);
    }
}
